package com.wdb.modules.system.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wdb.modules.system.domain.DictDetail;
import com.wdb.modules.system.domain.vo.DictDetailQueryCriteria;
import com.wdb.modules.system.domain.vo.QueryDictDetailReqDTO;
import com.wdb.modules.system.mapper.DictDetailMapper;
import com.wdb.modules.system.service.DictDetailService;
import com.wdb.utils.PageResult;
import com.wdb.utils.PageUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: wendaobai@qq.com
 * @date: 2024/1/22 0022 16:45
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class DictDetailServiceImpl extends ServiceImpl<DictDetailMapper, DictDetail>
    implements DictDetailService {
  private final DictDetailMapper dictDetailMapper;

  @Override
  public PageResult<DictDetail> findAll(QueryDictDetailReqDTO queryDictDetailReqDTO) {
    DictDetailQueryCriteria criteria = new DictDetailQueryCriteria();
    criteria.setDictName(queryDictDetailReqDTO.getDictName());
    criteria.setLabel(queryDictDetailReqDTO.getLabel());
    Page<DictDetail> page = new Page<>();
    page.setSize(queryDictDetailReqDTO.getSize());
    page.setCurrent(queryDictDetailReqDTO.getCurrent());
    Page<DictDetail> all = dictDetailMapper.findAll(criteria, page);

    PageResult<DictDetail> pageResult = PageUtil.toPage(all);
    return pageResult;
  }

  @Override
  public List<DictDetail> getAll(QueryDictDetailReqDTO queryDictDetailReqDTO) {
    return null;
  }

  @Override
  public void create(DictDetail resource) {
    resource.setDictId(resource.getDict().getId());
    save(resource);
  }

  @Override
  public void update(DictDetail resource) {
    resource.setDictId(resource.getDict().getId());
    saveOrUpdate(resource);

  }

  @Override
  public void delete(Long id) {
    removeById(id);
  }
}
